<template>
  <div>
    <el-table
      :data="storehouseList"
      border
      style="width: 100%"
      :height="$store.state.app.tableHeight"
    >
      <el-table-column
        label="仓库名称"
        width="180"
      >
        <template slot-scope="scope">
          {{ scope.row.warehouse_content.warehouse_name }}
        </template>
      </el-table-column>
      <el-table-column
        prop="storehouse_name"
        label="库位名称"
        width="180"
      />
      <el-table-column
        prop="desc"
        label="名称描述"
      />
      <el-table-column
        prop="inventory"
        label="库存能力"
      />
      <el-table-column
        prop=""
        label="操作"
      >
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="handleCheck(scope.row)">查看</el-button>
          <el-button type="text" size="small" @click="resetStorehouseInfo(scope.row)">修改</el-button>
          <del-btn :title="'是否确认删除名称为 “' + scope.row.storehouse_name + '” 的库位？'" button-text="删除" @onConfirm="delFun(scope.row)" />
        </template>
      </el-table-column>
    </el-table>
    <storehouse-form ref="storehouseForm" :title="dialogTitle" :warehouse-list="warehouseList" @reloadData="reloadFun" />
  </div>
</template>

<script>
import delBtn from '@/components/DelConfirm'
import storehouseForm from './storehouse-form'
import { operationStorehouse } from '@/api/wms'
export default {
  components: {
    delBtn,
    storehouseForm
  },
  props: {
    storehouseList: {
      type: Array,
      default() {
        return []
      }
    },
    warehouseList: {
      type: Array,
      default() {
        return []
      }
    }
  },
  data() {
    return {
      dialogTitle: ''
    }
  },
  methods: {
    delFun(row) {
      const data = {
        type: 3,
        id: row.id
      }
      operationStorehouse(data).then(res => {
        if (res.code === 200) {
          this.$message.success('库位删除成功！')
          this.$emit('reloadFun')
        } else {
          this.$message.info('操作失败！请重试')
        }
      })
    },
    reloadFun() {
      this.$emit('reloadFun')
    },
    handleCheck(row) {
      this.dialogTitle = '查看'
      this.$refs.storehouseForm.dialogAddNew = true
      this.$refs.storehouseForm.storehouseForm.storehouse_name = row.storehouse_name
      this.$refs.storehouseForm.storehouseForm.warehouse_id = row.warehouse_id
      this.$refs.storehouseForm.storehouseForm.desc = row.desc
      this.$refs.storehouseForm.storehouseForm.id = row.id
      this.$refs.storehouseForm.storehouseForm.inventory = row.inventory
      this.$refs.storehouseForm.type = 2
      this.$refs.storehouseForm.isDisable = true
    },
    resetStorehouseInfo(row) {
      this.dialogTitle = '修改'
      this.$refs.storehouseForm.dialogAddNew = true
      this.$refs.storehouseForm.storehouseForm.storehouse_name = row.storehouse_name
      this.$refs.storehouseForm.storehouseForm.warehouse_id = row.warehouse_id
      this.$refs.storehouseForm.storehouseForm.desc = row.desc
      this.$refs.storehouseForm.storehouseForm.id = row.id
      this.$refs.storehouseForm.storehouseForm.inventory = row.inventory
      this.$refs.storehouseForm.type = 2
      this.$refs.storehouseForm.isDisable = false
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
